/**
 * 门户模块，提供门户网站的动态及静态访问
 * 
 * @Date: 2016-1-25
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */

define(["jquery","sysmanMain","ajaxServ","ckeditor-jquery","nivo",
	"commonServ","loginSignModule","twbsPagination","dutiesView","dutiesComplain"],
		function($,sysmanMain,ajaxServ,ckeditor,nivo,
			commonServ,loginSign,twbsPagination,dutiesView,dutiesComplain) {
			
		'use strict';
		
		var _rootpath,_moduleConfig,curpageParam,_count = 0;
		var _pageRows = 20,_page=0;
		
		//查询条件临时变量
		var _oldConditionStr,_newConditionStr;
		/**
		 * 当前点击文档类型
		 */
		var clickedTypeCode;
		
		
		/**
		 * 查询条件对象
		 */
		var _searchEl;
		
		
		/**
		 * 当前页
		 */
		var currentPage;
		
		//获取附件列表url
		var uploadListurl = '/portal/getInitListDomain';
		
		var public_method ={
			
			/**
			 * 初始化方法，查找页面定义的动态元素
			 * @param _options.rootid 动态元素根节点
			 * @param _options.selector 动态元素选择器
			 */
			init:function(_options){
				
				$.messager.progress({
					msg:'loading...',
					interval:1000
				});
				var _defaultConfig = {
					rootid:null,					
					moduCode:null,
					initialized:false
				}
				
				$.extend(_defaultConfig,_options)
				
				
//			    public_method.initText();
			    
			    
			    
			    
			    public_method.initTopList(_defaultConfig)
				public_method.initList(_defaultConfig)
				public_method.initSlideImage(_defaultConfig)
				public_method.initZouma(_defaultConfig)
				
				$.messager.progress('close')
				private_method.initLogin();
			},
			/**
			 * 初始化首页文字
			 */
			initText:function(){
				//医院前置名称
			    var pre_title = commonServ.getPreTitle()
			    var _preTitle = $("span.pre-title")
			    _preTitle.text(pre_title)
			    
			    //医院前置名称
			    var ft_title = commonServ.getFootTitle()
			    var _ft_title = $("span.foot-title")
			    _ft_title.text(ft_title)
			    
			    //医院名称
				var org_name = commonServ.getHostpital()				
			    var _orgEl = $("span.hospital-name")
			    _orgEl.text(org_name)
			    
			    //医院地址信息
			    var addr = commonServ.getCommonConfig({configName:'addr'})
			    var _addr = $("h5.addr")
			    _addr.text(addr)
			    
			    //医院电话信息
			    var phone = commonServ.getCommonConfig({configName:'phone'})
			    var _phone = $("h5.phone")
			    _phone.text(phone)
			    
			    //医院邮政编码
			    var postcode = commonServ.getCommonConfig({configName:'postcode'})
			    var _postcode = $("h5.postcode")
			    _postcode.text(postcode)
			    
			    //医院英文名称
			    var ename = commonServ.getTitleConfig({configName:'ename'})
			    var _enameEl = $("span.en-title")
			    _enameEl.text(ename)
			    
			    var title_list = commonServ.getTitleConfig()
			    var _listEl = $('div.foot-title-list')
			    if(title_list && title_list.foot_title && _listEl.length>0){
			    	var _html = '<h5>'+org_name+'</h5>',
			    	lists = title_list.foot_title;
			    	
			    	for(var i=0;i<lists.length;i++){
			    		var _tmpHtml = '<h5>'+lists[i].name+'</h5>'
			    		_html += _tmpHtml;
			    	}
			    	_listEl.empty()
			    	_listEl.append(_html)
			    }
			},
			/**
			 * 加载页面模板
			 * @param _options.target 目标容器对象
			 * @param _options.pageUrl 目标页面url
			 * @param _options.moduleUrl 模板url
			 */
			loadPart:function(_options){
				
				private_method.loadPart(_options)
			},
			
			/**
			 * 
			 */
			initList:function(_options){
				var _defaultConfig = {
					rootid:null,
					selector:'div.portal-list'					
				}
				
				$.extend(_defaultConfig,_options)
				
				private_method.initList(_defaultConfig)
			}
			
			,
			
			/**
			 * 
			 */
			initTopList:function(_options){
				var _defaultConfig = {
					rootid:null,
					selector:'div.portal-top-list'					
				}
				
				$.extend(_defaultConfig,_options)
				
				private_method.initTopList(_defaultConfig)
			}
			
			,
			
			/**
			 * 
			 */
			initSlideImage:function(_options){
				var _defaultConfig = {
					rootid:null,
					selector:'div.portal-slide-image'					
				}
				
				$.extend(_defaultConfig,_options)
				
				private_method.initSlideImage(_defaultConfig)
			},
			
			/**
			 * 初始化内容页
			 * @param _options.id
			 * @param _options.type
			 * @param _options.lobid
			 */
			initContentPage:function(_options){
				
				
				//获取页面参数
				var _param = window.location.search
				var _parray = _param.split('&');
				if(_parray.length>0){
					for(var i=0;i<_parray.length;i++){
						var _p = _parray[i];
						if(_p){
							
							var _array = _p.split('=');
							if(_array.length=2){
								if(_array[0]){								
								
									switch(_array[0]){
									case 'docid':
										_options.id = _array[1];
										break;
									case 'code':
										_options.code = _array[1];
									}									
								}									
							}
						}						
					}
				}
				var org_name = commonServ.getHostpital()
			    var _orgEl = $("span.hospital-name")
			    $(_orgEl).text(org_name)
				private_method.initContentPage(_options);
			},
			
			/**
			 * 初始化内容列表页
			 * 
			 */
			initContentList:function(_options){
				//获取页面参数
				var _param = window.location.search
				
				var _jsonParam = {}
				if(_param){
					_param = _param.substring(1,_param.length);
					//分解参数名值对
					var _array = _param.split('&');
					if(_array &&  _array.length>0){
						for(var i=0;i<_array.length;i++){
							
							var _nv = _array[i].split('=');							
							
							if(_nv[0]){
								if(_nv[1]){
									_jsonParam[_nv[0]]=_nv[1];
								}else{
									_jsonParam[_nv[0]]=null;
								}
							}
						}
					}
				}
				
				
				
				
				var org_name = commonServ.getHostpital()
				
			    $("span.hospital-name").text(org_name);
			    
			    $('form.condition-form').form({
			    	onSubmit:private_method.doSearch
			    })
			    private_method.initContentList(_jsonParam);
			}
			
			,
			/**
			 * 初始化走马灯
			 */
			initZouma:function(_options){
				var _defaultConfig = {
					rootid:null,
					selector:'div.portal-zouma-image'					
				}
				
				$.extend(_defaultConfig,_options)
				
				private_method.initZoumaImage(_defaultConfig)
//				private_method.initSlideImage(_defaultConfig)
			}
			,
			openPage:function(e){
				private_method.openPage(e);
			}
			
			
		}
		
		var private_method ={
			initLogin:function(){
				$("a.btn").bind('click',loginSign.loginclick);
			 
			 $(document).keypress(function(e) {  
			    // 回车键事件  
			       if(e.which == 13) {  
			           loginSign.loginclick();  
			       }  
			   }); 
			},
			/**
			 * 初始化方法，查找页面定义的动态元素
			 * @param _options.rootid 动态元素根节点
			 * @param _options.selector 动态元素选择器
			 */
			init:function(_options){
				if(window.console){
					console.log('portal init loaded ...')
				}
				
				
				if(_options  && _options.selector){
					
					var rootid
					if(!_options.rootid){
						rootid = 'body'
					}else{
						rootid = '#' + _options.rootid
					}
					var _el = $(rootid + ' ' +_options.selector)
					
					$.each(_el,function(i,e){
						private_method.loadPart({target:e})
					})						
					
				}
			},
			
			initList:function(_options){
				if(window.console){
					console.log('portal init loaded ...')
				}
				
				var _windowWidth = $(document).width();
				var _url ='/portal/getTypeListDomainConcat'
				
				if(_options  && _options.selector){
					//获取容器dom对象
					var rootid
					if(!_options.rootid){
						rootid = 'body'
					}else{
						rootid = '#' + _options.rootid
					}
					var _el = $(rootid + ' ' +_options.selector)
					
					
					if(_el.length>0){
						//循环查询页面数据块定义
						for(var j=0;j<_el.length;j++){
							var _param = {
								windowWidth:_windowWidth
							}
							
							var _condition={}		
							var el = _el[j]
							if(el){

								//获取typename
								var _typename =$(el).attr('typename')
								var _typeid =$(el).attr('typeid')
								var _rows =$(el).attr('content-size')
								
								var _nameLength = $(el).attr('content-type')
								if(_typeid){
									_condition.id=_typeid
									
								}else{
									if(_typename){
										_condition.typeCode=_typename
																			
									}
								}
								_param.condition = _condition
								if(_rows){
									_param.rows=_rows
								}
								
								//判断是否投诉举报
								if(_typename=='complaint'){									
									private_method.appendComplain(
										{
											target:el
										}
									);
								}else{
									$.ajax({
										url: _url,
										type:'post',
										async:false,
										data:_param,																		
										success:function(result){
											var _aParam = {
												target:el,
												data:result
											}
											
											if(_nameLength && _nameLength==='longName'){
												_aParam.longName = true;
											}
											private_method.appendList(_aParam)									
										},
										failure:function(result){
											if(window.console){
												console.log('ajax call failured ...')
											}
										}
									})
								}
							}
							
						}
						
//						private_method.getDocList(_param)
					}					
					
					private_method.bindContentPageClick()
				}
			}
			,
			
			initTopList:function(_options){
				if(window.console){
					console.log('portal init loaded ...')
				}
				var _url ='/portal/getTypeListDomain'
				
				if(_options  && _options.selector){
					//获取容器dom对象
					var rootid
					if(!_options.rootid){
						rootid = 'body'
					}else{
						rootid = '#' + _options.rootid
					}
					var _el = $(rootid + ' ' +_options.selector)
					
					
					if(_el.length>0){
						//循环查询页面数据块定义
						for(var j=0;j<_el.length;j++){
							var _param = {},_condition={}		
							var el = _el[j]
							if(el){
//								_param = {target:el}
								//获取typename
								
								var _rows =$(el).attr('content-size')
								
								//置顶条件
								_condition.state_id =1
								_condition.isTop = 1;
								_param.condition = _condition
								if(_rows){
									_param.rows=_rows
								}
								
								$.ajax({
									url: _url,
									type:'post',
									async:false,
									data:_param,																		
									success:function(result){private_method.appendTopList({
										target:el,
										data:result
										})									
									},
									failure:function(result){
										if(window.console){
											console.log('ajax call failured ...')
										}
									}
								})
							}
						}
						
//						private_method.getDocList(_param)
					}					
					
					private_method.bindContentPageClick()
				}
			}
			,
			/**
			 * @param _options.id
			 * @param _options.type
			 * @param _options.lobid
			 */
			initContentPage:function(_options){
				
				if(window.console){
					console.log('initContentPage loaded and starting...')
				}
				var _defaultConfig = {
				}
				
				_defaultConfig =$.extend({},_defaultConfig,curpageParam,_options)
				if(_options.id){
					//查询页面内容
					var _url = '/portal/getContentOne';
					
					var _param = {
						url:_url,
						data:{docid:_options.id},
						success:function(data){
							if(data){
								if(data.archiveContent && data.archiveContent>0){
									private_method.initArchiveContent(data)
									
								}else{
									if(data.name){
										//文档标题
										var contentHeaderEl = $('span.page-title')
										
										if(contentHeaderEl.length==1){
											$(contentHeaderEl).html(data.name)
										}
									}
								
									if(data.typeName){
										//文档类型
										var contentHeaderEl = $('span.doctype')
										
										if(contentHeaderEl.length==1){
											$(contentHeaderEl).html('文档类别:'+data.typeName)
										}
									}															
									
									//发布人员
									var public_dept_user
									var contentHeaderEl = $('span.public_dept_user')
								
									if(contentHeaderEl.length==1){
										if(data.public_dept_name){
											public_dept_user = '发布人: ' +data.public_dept_name
											if(data.public_user_name){
												public_dept_user += ' ' + data.public_user_name;
											}
										}else{
											if(data.public_user_name){
												public_dept_user = '发布人: ' +data.public_user_name
											}
										}
										if(public_dept_user)
										$(contentHeaderEl).html(public_dept_user)
									}
								
								
									if(data.public_date){										
										
										//发布时间										
										var contentEl = $('span.public_date')
										if(contentEl.length==1){
											$(contentEl).html(data.public_date)
										}
									}
									
									//浏览点击量
									var click_count
									var clickCntEl = $('span.click_count')
								
									if(clickCntEl.length==1){
										if(data.click_count){
											click_count = '点击量: ' +data.click_count
											
										}
										if(click_count)
										$(clickCntEl).html(click_count)
									}
									
									if(data.typeCode && data.typeCode=='dutieslist'){
										dutiesView.loadPage({
											container:$(' .content-text'),
											data:data.form_content
										})
									}else{								
										
										if(data.lob_contents){										
											
											//文档内容										
											var contentEl = $('div.content-text')
											if(contentEl.length==1){
												$(contentEl).html(data.lob_contents)
											}
										}
									
									
										if(window.console){
											console.log(' archive loading ...')
										}
										//文档附件
										var _el = $('.container');
										var _param = {
											url: uploadListurl,
											data:{bizno:data.id,bizcode:data.typeCode},
											type: 'post',
											success:function(data){
												
												var _html ='';
												if(data && data.rows){
													
													$.each(data.rows,function(i,o){
														var _tmp = '<a class="archive-info" aid="'+o.id+'">'+o.filename+'</a>';
														if(!_html){
															_html += _tmp
														}else{
															_html += ' , ' + _tmp;
														}
													})
												}
												
												if(_html){
													_html = '附件:'+_html;
													_el.append(_html);
												}
												
												//绑定点击事件
												var file_btn = $(' .archive-info')
												if(file_btn.length>0){
													file_btn.unbind('click')
													file_btn.bind('click',	private_method.downloadFile)
												}
											}
										}
										
										$.ajax(_param);
									}
								}
							}
						}						
					}
					
					$.ajax(_param)
					//附加页面内容
					
					//显示页面内容
				}
				
			},
			
			/**
			 * 附件直接显示为页面内容
			 */
			initArchiveContent:function(data){
				
				if(window.console){
					console.log(' archiveContent loading ...')
				}
				if(data){
					
					if(data.typeName){
						//文档类型
						var contentHeaderEl = $('span.doctype')
						
						if(contentHeaderEl.length==1){
							$(contentHeaderEl).html('文档类别:'+data.typeName)
						}
					}
					
					//发布人员
					var public_dept_user
					var contentHeaderEl = $('span.public_dept_user')
				
					if(contentHeaderEl.length==1){
						if(data.public_dept_name){
							public_dept_user = '发布人: ' +data.public_dept_name
							if(data.public_user_name){
								public_dept_user += ' ' + data.public_user_name;
							}
						}else{
							if(data.public_user_name){
								public_dept_user = '发布人: ' +data.public_user_name
							}
						}
						if(public_dept_user)
						$(contentHeaderEl).html(public_dept_user)
					}
					
					if(data.public_date){										
										
						//发布时间										
						var contentEl = $('span.public_date')
						if(contentEl.length==1){
							$(contentEl).html(data.public_date)
						}
					}
					
					//附件内容
					var _p = {
						url	: '/portal/getContentArchive',
						data:{docid:data.id,bizcode:data.typeCode},
						success:function(_data){
							if(_data && _data.rows ){
								if((_data.rows)[0]){
							
								
									var t = (_data.rows)[0]
									//文档内容										
									var contentEl = $('div.content-text')
									if(contentEl.length==1){
										$(contentEl).html(t.content)
									}
									
									
								}
								
								
								
								//文档附件
								var _el = $('.archive-container');
								var _html ='<h4>';								
								$.each(_data.rows,function(i,o){
									var _tmp = '附件: <a class="archive-info" aid="'+o.id+'">'+o.fileName+'</a>';
									
									_html = _html?_html+'</br>'+_tmp:_tmp;									
								})												
												
								if(_html){
									_html = _html + '</h4>';
									_el.append(_html);
								}
								
								//绑定点击事件
								var file_btn = $(' .archive-info')
								if(file_btn.length>0){
									file_btn.unbind('click')
									file_btn.bind('click',	private_method.downloadFile)
								}
							}
						}
						,
						error:function(){
							
							
						}						
					}
					$.ajax(_p);
				}
			}
			,
			
			/**
			 * @param _options.typename 分类名称
			 */
			initContentList:function(_options){
				if(window.console){
					console.log('initContentList loaded and starting...')
				}
				var _defaultConfig = {
				}
				
				$.fn.twbsPagination.defaults = 
					$.extend(
						$.fn.twbsPagination.defaults,
						{
							first: '首页',
					        prev: '上页',
					        next: '下页',
					        last: '末页'
					    })
				_defaultConfig =$.extend({},_defaultConfig,curpageParam,_options)
				
				
				var _data
				
				if(_options.typeCode){
					//查询页面内容
					var _url = '/portal/getDoctypeListDomain';
					var _typecode = _options.typeCode
					
								
					if(_typecode.indexOf(',')>0){
						_data = {bizcode_in:_options.typeCode}
					}else{
						_data = {bizcode:_options.typeCode}
					}
					
					//判断分类查询方式
					if(_options.listType && _options.listType==='parent'){
						_url = '/portal/getDoctypeSubListDomain';
					}else{
						_data = {condition:_data};
					}
					
					var _param = {
						url:_url,
						data:_data,
						type:'post',
						success:function(data){
							if(data){								
								
								//设置文档分类内容
								if(data.total){
									
									var _row = data.rows[0];
									clickedTypeCode = _row.bizcode;
									//只有一项分类
									if(data.total==1){
										
								   		$('div.main-item span.red').text(data.rows[0].name);
								   		
								    }else{
										//文档标题
										var typeGroupEl = $('div.sidebar')
										
										if(typeGroupEl.length==1){
											var _rows = data.rows
											var _count = data.total,_html=''
											for(var i=0;i<_count;i++){
												_html +='<a href="javascript:void(0);" class="list-group-item" typeCode="' +data.rows[i].bizcode+'">'
													+'<h4 class="content-type"><span class="red">'
													+data.rows[i].name +'</span></h4></a>'
											}
											$(typeGroupEl).append(_html)
										}				
										
								    }
								    //绑定文档类型点击事件
									$('a.list-group-item').unbind('click');
									$('a.list-group-item').bind('click',private_method.typeClick);
									
									//绑定查询事件
									$('a.search-btn').unbind('click');
									$('a.search-btn').bind('click',private_method.doSearch);
									
									$(document).keypress(function(e) {  
									    // 回车键事件  
								       if(e.which == 13) {
								           private_method.doSearch();  
								       }  
								   });
								   
								   private_method.typeClick();
								   
								}								
							}
						}						
					}					
					$.ajax(_param)					
				}
			},
			
			/**
			 * @param 
			 */
			typeClick:function(e){
				if(e && e.currentTarget){
					var _el = e.currentTarget
					clickedTypeCode = $(_el).attr('typeCode')
				}
				if(clickedTypeCode){
					
					var _url = '/portal/getTypeListDomain';
					var _data = {typeCode:clickedTypeCode}
					var _param = {
						url:_url,
						data:{condition:_data},
						type:'post',
						success:function(data){							
							
							var _param = {
								total:data.total
							}
							//生成pagination							
							private_method.initPagination(_param);
							private_method.doSearch();
							
							
						}
					}
					$.ajax(_param);
				}
			},
			
			/**
			 * 初始化分页
			 * @param _options.page
			 * @param _options.total
			 */
			initPagination:function(_options){
				if(_options.total && _options.total >0){
					var _param = {
						totalPages:Math.ceil(parseInt(_options.total)/_pageRows),
						visiblePages:5,
						onPageClick:function(event,page){
							currentPage = page;
					  		var _param={
					  			page:page,
					  			condition:{typeCode:clickedTypeCode}					  			
					  		}
							private_method.pageClick(_param);
						}
					}
					
					var _el = $('div.pagination').twbsPagination(_param)
				}
				
			}
			,
			/**
			 * 执行查询
			 */
			doSearch:function(){
				var _condition = private_method.getCondition()		
				
				private_method.pageClick(_condition)				
			},
			getSearchEl:function(){
				if(!_searchEl){
					_searchEl = $('form.condition-form #searchParam')			
				}
				
				return _searchEl
				
			},
			/**
			 * 获取查询参数
			 */
			getCondition:function(){
				var retVal = {}
				if(clickedTypeCode){
					retVal = {condition:{typeCode:clickedTypeCode}}
					var _condition = private_method.getSearchEl().val();
					if(_condition){
						var _fuzzy ={														
							fuzzy:{name_like:_condition,
							public_dept_name_like:_condition,
							public_user_name_like:_condition,
							public_date_like:_condition}
						}
						$.extend(retVal,_fuzzy)
					}					
				}
				return retVal;
			},
			/**
			 * 点击文档类型事件
			 */
			pageClick:function(_options){
				//执行查询
				var _param = {
					page:currentPage,
					rows:_pageRows
				}
				var _url = '/portal/getTypeListDomain';
				
				var _data = $.extend(_param,private_method.getCondition(),_options)			
				
				
				$.ajax({
					url:_url,
					data:_data,
					type:'post',
					success:private_method.refreshPage
				})
				
			},
			
			refreshPage:function(data){
				//清除原有数据
				
				var rePage
				
				_newConditionStr =private_method.getSearchEl().val()				
					
				//查询条件变化
				if(!_oldConditionStr || _oldConditionStr!=_newConditionStr){
					rePage = true;
					_oldConditionStr = _newConditionStr;					
				}else{
					rePage = false;
				}
				
				var _el = $('div.table-responsive tr.data-row')
				$(_el).remove();
				if(rePage){
					private_method.initPagination({total:data.total})
				}
				
				
				if(data && data.rows && data.rows.length>0){
					var _el = $('div.table-responsive tbody');
					var _rows = data.rows;
					var _html='';
					var _count = data.rows.length
					
					//获取页面站点
					var _sitePath = window.location.pathname;
					
					var _sp = _sitePath.split('/');
					
					//设置默认站点
					var _site = 'honest';
					if(window.console){
						console.log('site check ...');
					}
					if(_sp.length>=3){
						var _site = _sp[2];
						if(_site && _site.indexOf('get')<0){
							
							_site = _sp[2];
						}
					}
					for(var i=0;i<_count;i++){
						var _tmpRow = {
							public_date:''
						}
						var _row = _rows[i]
						var _date ='', _dept = '',_user ='';
						
						if(!("public_date" in _row) || (!_row.public_date)){
							_date = _row.createTime
						}else{
							_date = _row.public_date
						}
						
						if(_row.public_dept_name){
							_dept = _row.public_dept_name
						}
						
						if(_row.public_user_name){
							_user = _row.public_user_name
						}
						
						
						
						_html += '<tr class="data-row">'+		                  
		                  '<th class="col-md-6"><a href="/portal/'+_site+'/getPage?code=content&docid='+_row.id+'" target="_blank">'+_row.name+'</a></th>'+
		                  '<th class="col-md-2 placeholder">'+_dept+'</th>'+
		                  '<th class="col-md-2 placeholder">'+_user+'</th>'+
		                  '<th class="col-md-2 placeholder">'+_date+'</th>'+
		                  '</tr>';					     
					}
					
					$(_el).append(_html);
				}
				//根据
			},
			/**
			 * 初始化图片轮播
			 */
			initSlideImage:function(_options){
				if(window.console){
					console.log('portal initSlideImage loaded ...')
				}
				var _url ='/portal/getPicListDomain'
				
				if(_options  && _options.selector){
					//获取容器dom对象
					var rootid
					if(!_options.rootid){
						rootid = 'body'
					}else{
						rootid = '#' + _options.rootid
					}
					var _el = $(rootid + ' ' +_options.selector)
					
					
					if(_el.length>0){
						//循环查询页面数据块定义
						for(var j=0;j<_el.length;j++){
							var _param = {},_condition={}		
							var el = _el[j]
							if(el){
//								_param = {target:el}
								//获取typename
								var _typename =$(el).attr('typename')
								var _typeid =$(el).attr('typeid')
								var _rows =$(el).attr('content-size')
								
								if(_typeid){
									_condition.id=_typeid
									
								}else{
									if(_typename){
										_condition.typeCode=_typename
																			
									}
								}
								_param.condition = _condition
								if(_rows){
									_param.rows=_rows
								}
								
								$.ajax({
									url: _url,
									type:'post',
									async:false,
									data:_param,																		
									success:function(result){private_method.appendSlideImage({
										target:el,
										data:result
										})									
									},
									failure:function(result){
										if(window.console){
											console.log('ajax call failured ...')
										}
									}
								})
							}
						}
						
//						private_method.getDocList(_param)
					}
			}
			},
			
			/**
			 * 初始化走马灯组件
			 */
			initZoumaImage:function(_options){
				if(_options  && _options.selector){
					//获取容器dom对象
					var rootid
					if(!_options.rootid){
						rootid = 'body'
					}else{
						rootid = '#' + _options.rootid
					}
					var _el = $(rootid + ' ' +_options.selector)
					var _url ='/portal/getPicListDomain'
					
					if(_el.length>0){
						//循环查询页面数据块定义
						for(var j=0;j<_el.length;j++){
							var _param = {},_condition={}		
							var el = _el[j]
							if(el){
//								_param = {target:el}
								//获取typename
								var _typename =$(el).attr('typename')
								var _typeid =$(el).attr('typeid')
								var _rows =$(el).attr('content-size')
								
								if(_typeid){
									_condition.id=_typeid
									
								}else{
									if(_typename){
										_condition.typeCode=_typename
																			
									}
								}
								_param.condition = _condition
								if(_rows){
									_param.rows=_rows
								}
								
								$.ajax({
									url: _url,
									type:'post',
									async:false,
									data:_param,																		
									success:function(result){private_method.appendZoumaImage({
										target:el,
										data:result
										})									
									},
									failure:function(result){
										if(window.console){
											console.log('ajax call failured ...')
										}
									}
								})
							}
						}
						
//						private_method.getDocList(_param)
					}
				}
			},
			/**
			 * 加载页面模板
			 * @param _options.target 目标容器对象
			 * @param _options.pageUrl 目标页面url
			 * @param _options.moduleUrl 模板url
			 */
			loadPart:function(_options){
				
				if(_options && _options.target){
					
					var _pageUrl = $(_options.target).attr('src');
					if(_pageUrl){
						$.ajax({
							url:_pageUrl,
							success:function(data){
								private_method.replaceTarget({target:_options.target,content:data})
							}
						})
						
					}
				}
					
			},
			/**
			 * 替换目标容器页面
			 * @param _options.target	目标容器对象
			 * @param _options.content	目标html
			 */
			replaceTarget:function(_options){
				if(_options.target && _options.content){
					$(_options.target).append(_options.content)
				}
			}
			,
			getRootPath:function(){
				var patharr = window.location.pathname.split('/')
        		var rootPath = patharr[1]
        		return rootPath
			},
			
			/**
			 * portal列表页面加载投诉
			 * @param _options.target
			 */
			appendComplain:function(_options){
				if(window.console){
					console.log('complain loaded ...')
				}
				var _html = '</br>' +
						'<div calss="row">' +
						'<div class="articles_contents">来信请寄：湘潭市第五人民医院纪检监察室</div></div>' +
						
						'<div class="row"><div class="col-md-12"><div class="articles_contents">来访请到：门诊医技楼三楼纪检监察室</div></div></div>' +
						
						'<div class="row"><div class="col-md-12"><div class="articles_contents">举报电话：0731-52875051</div></div></div>'+
						'<div class="row"><div class="col-md-12"><div class="articles_contents">网上举报：xtswyyjw@163.com</div></div></div>'+
						'</br></br>' +
						
						'<div class="row"><div class="articles_date"> <a href="javascript:void(0);" class="click-complain">投诉直通车</a></div></div>'
					
				$(_options.target).append(_html);
				
				var $c_bt = $('a.click-complain')
				if($c_bt.length>0){
					$c_bt.bind('click',function(){
						dutiesComplain.openPage()
					})
				}
			}
			,
			/**
			 * portal列表页面html加载
			 * @param _options.target
			 * @param _options.data
			 * @param _options.longName	长文件名称标志
			 */
			appendList:function(_options){
				
				var _html=""
				if(_options){
					if(_options.target && _options.data){
						
						var html_title 
						if(_options.data.total>0){
							
							
							$.each(_options.data.rows,function(i,e){
								
								
								
								var _t='';
								if(e.public_date){
									var t = e.public_date.split(' ');
									if(t.length>0){
										_t = t[0]
									}
								}
//								_html += '<div class="articles_img ' + _typename +'"><img class="tip" /></div>'
								_html += '<div class="row">'+
											'<div class="col-md-8 col-sm-7">' +
												'<a href=\"javascript:void(0);\" docid=\"'+ e.id + '\" class=\"doc-file\" lobid=\"'+e.lobid
									 			+'\">' +
									 				'<div class="articles_contents ' + e.typeCode +'">'+'* '+ e.name + '</div>' +
									 			'</a>' +
									 		'</div>'
								_html += '<div class="col-md-4 col-sm-5"><div class="articles_date '+ e.typeCode +'">'+ _t + '</div></div>'+
									'</div>'
							})
							
							
							$(_options.target).append(_html)
						}
					}
				}
				
			},
			
			/**
			 * portal列表页面html加载
			 * @param _options.target
			 * @param _options.data
			 */
			appendTopList:function(_options){
				
				var _html=""
				if(_options){
					if(_options.target && _options.data){
						
						
						if(_options.data.total>0){
							var _typename = _options.data.rows[0].typeName
							
							var _typeCode = _options.data.rows[0].typeCode
							
							
							$.each(_options.data.rows,function(i,e){				
//								_html += '<div class="articles_img ' + _typename +'"><img class="tip" /></div>'
								_html += '<a href=\"javascript:void(0);\" docid=\"'+ e.id + '\" class=\"doc-file \"  lobid=\"'+e.lobid +'\"><div class="top-list"><div><b>'+'* '+ e.name + '</b></div></div></a>'
								
							})
							
							
							$(_options.target).append(_html)
						}
					}
				}
				
			},
			appendZoumaImage:function(_options){
				var _html="",_url='/portal/getImage'
				
				
				if(_options){
					if(_options.target && _options.data){
						
						var html_title 
						if(_options.data.length>0){
							var _typename = _options.data[0].typeName
							
							var _typeCode = _options.data[0].typeCode
							
//							html_title = '<h3><span class="red">' +_options.data[0].typeName +'</span></h3>'
							_html += '<ul>'
							$.each(_options.data,function(i,e){				
//								_html += '<div class="articles_img ' + _typename +'"><img class="tip" /></div>'
								var _param = _url +'?id='+ e.id;
								_html += '<li style=\"display: block\";><img src=\"'+_param +'\"/></li>'																
							})
//							_html = html_title + _html
							_html += '</ul>'
							$(_options.target).append(_html)
							
							
							/**
							var zoumaParam = {
								maxLength:10,
								timer:5000,
								target:_options.target
							}							
							var handId;
							 handId = setInterval(
							 	function(){private_method.zoumaPlay({target:zoumaParam.target})}, 
							 	zoumaParam.timer);
							private_method.zoumaPlay({target:zoumaParam.target})

 							*/
							private_method.paoma({target:_options.target})
						}
					}
				}
			},
			
			/**
			 * @param _options.target
			 */
			zoumaPlay:function(_options){
//				if(window.console){
//					console.log('zouma played ...')
//				}
				var _target = $(_options.target).find('ul')
				var img = _target.children().eq(0);
                var left = img.children().eq(0).width();
                var _moveleft = -1*left;
                
                img.animate({ "marginLeft": _moveleft + "px" }, 'slow', function () {
                    //appendTo函数是实现走马灯一直不间断播放的秘诀。
                    //目前网上看到的很多走马灯，走到最后一张的时候，会立马闪回第一张，而不是继续从后往前推进，即是没有明白该函数的作用的原因
//                    if(window.console){
//                    	console.log('_moveleft:'+_moveleft)
//                    }
//                     $(this).css("margin-left", "auto").appendTo(_target);
                    $(this).css("margin-left", "auto")
                    
                    $(this).appendTo(_target);
                    
                });
			},
			
			//跑马灯
			paoma :function (_options){
				if(window.console){
					console.log(' ... paoma start ...');	
				}
				$.fn.imgscroll = function(o){
	
					var defaults = {
						speed	: 40,
						amount	: 0 ,
						width	: 1,
						dir		: "left"
					};
				
					o = $.extend(defaults,o);
				
					return this.each(function(){
						var _li = $('li',this);
				
						_li.parent().parent().css({overflow: "hidden", position: "relative"});
						_li.parent().css({margin: "0", padding: "0",overflow: "hidden", position: "relative","list-style": "none"});
						_li.css({position: "relative", overflow: "hidden"});
				
						if(o.dir == "left")
							_li.css({float: "left"})
						
						//初始大小
						var _li_size = 0;
						for(var i=0;i<_li.size();i++){
							_li_size += o.dir=="left"? _li.eq(i).outerWidth(true): _li.eq(i).outerHeight(true);
						}
				
						//循环所需要的元素
						var _tmpWidth = $(' .portal-zouma-image').width()
						if(o.dir == "left"){
							var _width = (_li_size * 10) + "px";
							_li.parent().css({width:  (_tmpWidth *4)+'px' });
						}
				
						_li.parent().empty().append(_li.clone()).append(_li.clone()).append(_li.clone());
						_li = $("li",this);
				
						//滚动
						var _li_scroll = 0;
						function goto(){
							_li_scroll += o.width;
				
							if(_li_scroll > _tmpWidth){
								_li_scroll = 0;
								_li.parent().css(o.dir == "left" ? {left :  -_li_scroll} : {top : -_li_scroll} );
								_li_scroll += o.width
							};
				
							_li.parent().animate(o.dir == "left" ? {left :  -_li_scroll} : {top : -_li_scroll},o.amount);
				
						}
				
						//开始
						var _move = setInterval(function(){ goto() ;},o.speed);
				
						_li.hover(function(){
							clearInterval(_move);
							
						},function(){
							clearInterval(_move);
							_move = setInterval(function(){ goto() ;},o.speed);
						});
					});
				
				};
				
				$(_options.target).imgscroll({
					speed	: 40,
					amount	: 0 ,
					width	: 1 ,
					dir		: "left"
				})
			},
			/**
			 * 生成图片dom对象
			 */
			appendSlideImage:function(_options){
				
				var _html="",_url='/portal/getImage'
				
				
				if(_options){
					if(_options.target && _options.data){
						
						var html_title 
						if(_options.data.length>0){
							var _typename = _options.data[0].typeName
							
							var _typeCode = _options.data[0].typeCode
							
//							html_title = '<h3><span class="red">' +_options.data[0].typeName +'</span></h3>'
							$.each(_options.data,function(i,e){	
								_html += '<div class="articles_img '+  _typename + '" style="position: absolute; z-index: 1; opacity: 0;">'
//								_html += '<div class="articles_img ' + _typename +'"><img class="tip" /></div>'
								var _param = _url +'?id='+ e.id;
								_html += '<img src="'+_param +'" data-thumb="'+_param+'" alt=""  />'
								_html +='</div>'
							})
//							_html = html_title + _html
							
							$(_options.target).append(_html)
							$(_options.target).nivoSlider({
								controlNav:false,
								directionNav:false,
								pauseTime:5000
							});
						}
					}
				}
				
			},
			//绑定页面点击链接
			bindContentPageClick:function(){
				var _pages = $('a.doc-file');
				$(_pages).unbind('click');
				$(_pages).bind('click',private_method.openPage);
			},
			openPage:function(e){
				
				
				if(window.console){
					console.log(' content openPage fired...')	
				}
				//获取页面站点
				var _sitePath = window.location.pathname;
				
				var _sp = _sitePath.split('/');
				
				//设置默认站点
				var _site = 'honest';
				if(_sp.length>=2){
					var _site = _sp[1];
					if(_site && _site.indexOf('get')<0){
						
						_site = _sp[1];
					}
				}
				var _url = '/portal/'+_site+'/getPage?code=content'
				
				if(e){
					var _target = e.currentTarget
					var _id = $(_target).attr("docid")
					var _type = $(_target).attr("docid")
					var _lobid = $(_target).attr("lobid")
					curpageParam = {id:_id,type:_type,lobid:_lobid}
					_url = _url + '&docid='+_id
					window.open(_url,'_blank')
				}
			}
			
			,
			downloadFile:function(e){
				var _btn = $(e.currentTarget)
				
				var _id = _btn.attr('aid')				
				
				var _url = '/portal/getFile';
				var form = $("<form>");
				form.attr('style','display:none');
				form.attr('target','');
				form.attr('method','post');
				form.attr('action',_url);
				var input1 = $("<input>");
				input1.attr('type','hidden')
				input1.attr('name','id')
				input1.attr('value',_id);
				$('body').append(form);
				$(form).append(input1);
				
				form.submit();
				form.remove();
			}
			,
			
			//获取页面站点
			getPageSite:function(){
				
				//获取页面站点
				var _sitePath = window.location.pathname;
				
				var _sp = _sitePath.split('/');
				
				//设置默认站点
				var _site = 'honest';
				if(_sp.length>=2){
					var _site = _sp[1];
					if(_site && _site.indexOf('get')<0){
						
						_site = _sp[1];
					}
				}
				return _site;
			}
				
		}
			
		
		return public_method;
			
})